<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta charset="utf-8" />
<meta name="description" content="Mailbox with some customizations as described in docs" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0" />
<%@ include file="/include/main_include.jsp"%>
</head>
<body class="easyui-layout">
<!-- 左部分 -->
	<div data-options="region:'west',title:'商家列表',split:true" style="width: 17%;">
		<div data-options="region:'north',border:false" style="height: 40px;">
				<div class="input-group">
							<input id="businessName" name="businessName"  type="text" class="form-control search-query"  placeholder="这里输入要查询商家名称">
							<span class="input-group-btn">
								<button type="button" class="btn btn-success btn-sm"  onclick="searchname()">
									<span class="ace-icon fa fa-search icon-on-right bigger-110"></span>
									搜索
								</button>
							</span>
					</div>
		</div>
		<div data-options="region:'center',border:false" style="height: 94.7%;">
			<table id="business_table"></table>
		</div>
	</div>

<!-- 右部分 -->
	<div data-options="region:'center',title:'明细列表',split:true" style="width: 80%; height: 100%;">
		<div data-options="region:'north',border:false" style="height:42px;">
			<div class="grsun-toolbar">
					 
					<button type="button" id="search" class="btn btn btn-toolbar btn-white btn-info no-border auth-hidden">
						<i class="ace-icon fa fa-search green bigger"></i>
						查询
					</button>
			</div>
		</div>
	<div data-options="region:'center',border:false" style="height: 94.7%;">
		<table id="data_table"></table>
	</div>  
	</div>
	<script type="text/javascript">
		var searchParams;
		$(function(){
			//添加按钮事件
			$('#add').on('click', function() {
				openedit('');
			});
			//修改按钮事件
			$('#edit').on('click', function() {
				var node = dataTable.datagrid('getSelected');
				if (node) {
					openedit(node.businessRecordId);
				} else {
					layer.msg('请选择一条数据！', {
						time : 1000
					})
				}
			});
			//删除按钮事件
			$('#del').on('click', function() {
				del();
			});
			//查询按钮事件
			$('#search').on('click', function() {
				opensearch();
			});
			
			refresh('');
		});
		
		var dataTable;
		var businessTable;
		 
		function searchname() {
			var a = $('#businessName').val()
			refresh(a);
			
		}
		// Table表格数据源
		function refresh(aa) {
			businessTable = $('#business_table').datagrid(BasicData.createDatagrid({
				url : rootpath + '/hhBusiness/list.do?name=' + aa,
				checkOnSelect : true,
				singleSelect : true,
				selectOnCheck : true,
				frozenColumns : [ [ { field : 'ck', checkbox : false, hidden:true },
					{ title : 'businessId', field : 'businessId', hidden : true } ] ],
				columns : [ [ { field : 'name', title : '商家名称', width : '97%', sortable : true, align : 'center' },
				{ field : 'phone', title : '电话', width : '12%', hidden : true },
				{ field : 'status', title : '是否禁用', hidden : true ,formatter:function(value,row,index){
					if(value==0){
						return "否";
					}else{
						return "是";
					}
				   }}, 
				{ field : 'addTime', title : '创建时间', hidden : true,formatter:function(value,row,index){
		        	return timestampToTime(value);
				   }
				} ] ],
				onDblClickRow : function(rowIndex, rowData) {
				},
				onClickRow : function(index, row) {
					dataTable.datagrid({
						url : rootpath + '/hhBusinessRecord/list.do?businessId=' + row.businessId
					});
				}
			}));
		}
		
		//Table表格数据源
		dataTable = $('#data_table').datagrid(BasicData.createDatagrid({  
			frozenColumns:[[
				{field:'ck',checkbox:true},
				{title:'businessRecordId',field:'businessRecordId',hidden:true}
			]],
			columns:[[
				{field:'type',title:'类型',width:'10%',sortable:true,align:'center',formatter:function(value,row,index){ 
					if(value==1){
						return '下订单'
					}else if(value==2){
						return '手续费'
					}else if(value==3){
						return '服务费'
					}else if(value==4){
						return '提现'
					}
					}}, 
				{field:'status',title:'状态',width:'10%',sortable:true,align:'center',formatter:function(value,row,index){
					if(value==1){
						return '已完成'
					}else if(value==0){
						return '未完成'
					} 
				}},
				{field:'addTime',title:'下单时间',width:'10%',sortable:true,align:'center',formatter:function(value,row,index){ return timestampToTime(value);  }},
				{field:'fromName',title:'付款方',width:'10%',sortable:true,align:'center'},
				{field:'toName',title:'收款方',width:'10%',sortable:true,align:'center'},
				{field:'amount',title:'金额',width:'10%',sortable:true,align:'center'},
				{field:'channel',title:'渠道',width:'10%',sortable:true,align:'center'},
				{field:'note',title:'说明',width:'10%',sortable:true,align:'center'}
			]],
			onDblClickRow:function(rowIndex, rowData){
				
			}
		}));  
		//打开查询窗体
		function opensearch(){
			layer.open({
				title : '查询条件',
				type : 2,
				btn : ['查询','重置'],
				yes : function(index,layero) {
					var iframeWin = window[layero.find('iframe')[0]['name']];
					searchParams = iframeWin.$("#searchForm").serialize();
					var newparam = iframeWin.$("#searchForm").serializeJSON();
					$.extend(newparam,dataTable.queryParams);
					$('#data_table').datagrid('load',newparam);
					layer.close(index);
				},
				btn2 : function(index, layero) {
					var iframeWin = window[layero.find('iframe')[0]['name']];
					iframeWin.$("#searchForm").form("clear");
					return false;
				},
				area : [ '80%', '80%' ],
				content : rootpath + '/hhBusinessRecord/toSearch.do?'+searchParams
			});
		}
		//编辑打开窗体
		function openedit(businessRecordId){
			layer.open({
				title : '信息',
				type : 2,
				btn : ['保存','关闭'],
				yes : function(index,layero) {
					var iframeWin = window[layero.find('iframe')[0]['name']];
					iframeWin.$("#dataForm").submit();
				},
				btn2 : function(index, layero) {
				},
				area : [ '80%', '80%' ],
				content : rootpath + '/hhBusinessRecord/toEdit.do?businessRecordId='+businessRecordId
			});
		}
		//删除
		function del() {
			var node = dataTable.datagrid('getSelected');
			if (node) {
				layer.confirm('您确定要删除吗？', {
					btn : [ '确定', '取消' ]
				}, function(index, layero) {
				    layer.close(index);
					$.uitools.showLoading();//打开处理中遮罩层
					$.ajax({
						cache : true,
						type : "POST",
						url : rootpath + '/hhBusinessRecord/delete.do',
						data : {
							businessRecordId : node.businessRecordId
						},
						error : function(request) {
							$.uitools.hideLoading();//关闭处理中遮罩层
							layer.msg('系统异常！', {
								icon : 2,
								time : 1000
							})
						},
						success : function(data) {
							$.uitools.hideLoading();//关闭处理中遮罩层
							if (data.code==0){
								layer.msg('删除成功！', {
									icon : 1,
									time : 1000
								}, function() {
									dataTable.datagrid('reload');
								})
							}else {
								layer.msg('删除异常！', {
									icon : 2,
									time : 1000
								})
							}
						}
					});
				}, function() {
				});
			} else {
				layer.msg('请选择一条数据！', {
					time : 1000
				})
			}
		}
	</script>
</body>
</html>